﻿using System.Web;
using cludg.Infrastructure.DI;

namespace cludg.Web
{
	public class InjectionsConfiguration : Core.BaseInjectionConfiguration
	{
		public override IDIContainer CreateContainer(HttpApplication application)
		{
			IDIContainer container = new Infrastructure.DI.Unity.DIContainer();

			// Registrations

			// DI container
			container.RegisterInstance<IDIContainer>(container);

			// Logging
			container.RegisterInstance<Infrastructure.Core.Logging.ILogger>(new Infrastructure.Core.Logging.Log4NetLogger("cludg.WebApp"));
	
			// Permission providers
			container.Register<Services.Security.Permissions.IPermissionProvider, Permissions.OffersPermisionProviders>("Offers", DILifetime.Singleton);
			container.Register<Services.Security.Permissions.IPermissionProvider, Permissions.StoryPermissionProvider>("Story", DILifetime.Singleton);
			container.Register<Services.Security.Permissions.IPermissionProvider, Permissions.AccountPermisionProviders>("Account", DILifetime.Singleton);

			// View model extensions providers
			container.Register<Core.ViewModels.Extensions.IViewModelExtensionProvider, ViewModels.Extensions.TestProvider>("test", DILifetime.PerResolve);

			// Menu providers
			container.Register<Core.Menu.INavigationMenuProvider, Menu.NavigationMenuProvider>("Main", DILifetime.PerResolve);

			// Controllers
			container.Register<Core.ControllerFactory.IControllerRegistry, Core.ControllerFactory.ControllerRegistry>(DILifetime.Singleton);
			container.Register<ControllerFactory.InjectedControllerFactory>(DILifetime.PerResolve);

			// View register
			container.Register<Core.ViewRegister.IViewRegisterContainer, Core.ViewRegister.ViewRegisterContainer>(DILifetime.Singleton);
			container.Register<Core.ViewModels.Extensions.IViewModelExtensionRegistry, Core.ViewModels.Extensions.ViewModelExtensionRegistry>(DILifetime.Singleton);
			container.Register<Core.Views.Extensions.IViewExtensionRegistry, Core.Views.Extensions.ViewExtensionRegistry>(DILifetime.Singleton);
			container.Register<Core.ViewEngines.ViewEngineUtil>(DILifetime.Singleton);
			container.Register<Core.ViewEngines.IViewEngineProvider,
				Core.ViewEngines.WebFormsViewEngineProvider>("WebFormsViewEngineProvider", DILifetime.Singleton);
			
			// Bootstrappers
			container.Register<Core.Bootstrappers.IBootstrapper, Bootstrappers.RoutesBootstrapper>("Routes", DILifetime.PerResolve);
			container.Register<Core.Bootstrappers.IBootstrapper, Bootstrappers.ControllerFactoryBootstrapper>("ControllerFactory", DILifetime.PerResolve);
			container.Register<Core.Bootstrappers.IBootstrapper, Bootstrappers.ViewRegisterBootstrapper>("Viewregister", DILifetime.PerResolve);
			container.Register<Core.Bootstrappers.IBootstrapper, Bootstrappers.ViewEnginesBootstrapper>("ViewEngines", DILifetime.PerResolve);

			// Notifiers
			container.Register<
				Web.Core.Notifications.Application.IApplicationNotifier, 
				Web.Core.Notifications.Application.ApplicationNotifier>(DILifetime.Singleton);
			container.Register<
				Web.Core.Notifications.Application.IApplicationNotificationSource,
				Web.Core.Notifications.Application.ApplicationNotifier>(DILifetime.Singleton);

			// Modules
			container.Register<Core.Modules.IModuleManager, Core.Modules.ModuleManager>(DILifetime.Singleton);

			return container;
		}
	}
}